package com.sourceQ.common.mq.redis.config;

import com.sourceQ.common.redis.configure.RedisConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.StringRedisTemplate;
import com.sourceQ.common.mq.redis.core.RedisMQTemplate;
import com.sourceQ.common.mq.redis.core.interceptor.RedisMessageInterceptor;

import java.util.List;

/**
 * @author: SourceQ
 * @create: 2024-04-15 15:04
 * @Description:Redis 消息队列 Producer(生产者) 配置类
 */
@Slf4j
@AutoConfiguration(after = RedisConfig.class)
public class SourceQRedisMQProducerAutoConfiguration {
    @Bean
    public RedisMQTemplate redisMQTemplate(StringRedisTemplate redisTemplate,
                                           List<RedisMessageInterceptor> interceptors) {
        RedisMQTemplate redisMQTemplate = new RedisMQTemplate(redisTemplate);
        // 添加拦截器
        interceptors.forEach(redisMQTemplate::addInterceptor);
        return redisMQTemplate;
    }

}
